<template>
  <div>
    <router-link v-show="showAbs" tag="div" to="/" class="header-abs">
      <div class="iconfont header-abs-back">&#xe624;</div>
    </router-link>
    <div
      class="header-fixed"
      v-show="!showAbs"
      :style="opacityStyle"
    >
      景点详情
      <router-link to="/">
        <div class="header-fixed-back iconfont">&#xe624;</div>
      </router-link>

    </div>
  </div>
</template>

<script>
export default {
  name: 'DetailHeader',
  data () {
    return {
      showAbs: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.handleScorll)
  },
  deactivated () {
    window.removeEventListener('scroll', this.handleScorll)
  },
  methods: {
    handleScorll () {
      const top = document.documentElement.scrollTop
      if (top > 60 && top < 140) {
        const opacity = (top / 140)
        this.opacityStyle = { opacity }
      }
      this.showAbs = (top < 60)
    }
  }
}
</script>

<style lang='stylus' scoped>
  @import '~styles/varibles.styl'
  .header-abs
    position absolute
    left .2rem
    top .2rem
    width .8rem
    height .8rem
    border-radius .4rem
    background-color rgba(0, 0, 0, .8)
    text-align center
    line-height .8rem
    &-back
      color #ffffff
      font-size .4rem
  .header-fixed
    position fixed
    height $headerHeight
    line-height $headerHeight
    left 0
    top 0
    right 0
    text-align center
    color #ffffff
    background $bgColor
    font-size .32rem
    .header-fixed-back
      position absolute
      left 0
      top 0
      width .64rem
      text-align center
      font-size .4rem
      color #fff
</style>
